<?php
class NewsController extends Zend_Controller_Action 
{

	public function init()
	{
		$this->AppUI = Zend_Auth::getInstance()->getIdentity();
		$this->objNews = Application_Model_News::getInstance();
	}

	public function indexAction()
	{
		$this->view->arrTopNews = $this->objNews->getLastest('career', 4);
		$this->render_right_column();
		$this->view->arrCategories = $this->objNews->categories('career');
		$this->view->objNews = $this->objNews;
	}

	public function categoryAction()
	{
		$params = array(
			'catid' => (int)$this->_request->getParam('catid', 0),
			'is_public' => 1,
			'object' => 'career',
			'page' => $this->_request->getParam('page'),
			'limit' => 10
		);
		$this->view->arrNews = $this->objNews->find($params, $total);
		$params['link'] = BASE_URL.'news?'.http_build_query(array_slice($params, 0, -2));
		$params['total'] = $total;
		$this->view->PAGE_LINKS = Common::generatePaginator($params);
		$this->view->category = $this->objNews->category_name($params['object'], $params['catid']);
		$this->render_right_column();
	}

	private function render_right_column()
	{
		$this->view->arrCategories = $this->objNews->categories('career');
		$this->view->arrLastestJobs = $this->objNews->getLastest('career', 10);
	}
	
	public function viewAction()
	{
		$news_id = $this->_request->getParam('news_id');
		if( $arrInfo = $this->objNews->get($news_id))
		{
			$this->view->arrInfo = $arrInfo;
			$this->view->category = $this->objNews->category_name($arrInfo['OBJECT'], $arrInfo['CATID']);
			$this->view->arrLastest = $this->objNews->getLastest($arrInfo['OBJECT'], 10, $arrInfo['ID']);
		}
		$this->render_right_column();
	}

	public function boxadviceAction()
	{
		$this->_helper->layout->disableLayout();
		$this->view->arrNews = $this->objNews->getLastest('career', 3);
	}
}